package com.beecloud.learning.charpter.three;

/**
 * Created with IntelliJ IDEA.
 * User: hengsun
 * Date: 3/27/17
 * Time: 5:28 PM
 * Description:
 */
public class VolatileVariables extends Thread {
    private
    boolean aSleep;

    public static void main(String[] args) throws InterruptedException {
        VolatileVariables variables = new VolatileVariables();
        variables.start();
        //Thread.sleep(20);
        UpdateThread updateThread = new UpdateThread(variables);
        updateThread.start();
    }

    public boolean isaSleep() {
        return aSleep;
    }

    public void setaSleep(boolean aSleep) {
        this.aSleep = aSleep;
    }

    @Override
    public void run() {
        while (!aSleep) {
            System.out.println("sleep is not right.................");
        }
    }
}

class UpdateThread extends Thread {
    private VolatileVariables volatileVariables;
    UpdateThread(VolatileVariables volatileVariables){
        this.volatileVariables = volatileVariables;
    }
    @Override
    public void run() {
        System.out.println("Prepare to update value.........");
        volatileVariables.setaSleep(true);
    }
}


